/*****************************************
Filename  : sw_uart_config.h
Author    : Prashant Mehta
Date	  : 26-06-2009
******************************************/
/*                   
*******************************************************************************************************************
*  Header file for configuring SOFTWARE UART     								  *
*  Timer 0 is set to 3 times the required baud rate because data sampling has to be done 3 times per bit	  *
*  Here Timer 0 of AtMega128 is used. Change the timer registers as per used uC					  *
*  UART can be configured using ATMEGA128 like UART control registers						  *
*  Any port pin can be made into Tx and  Rx pin by changing in macros below					  *
*  5,6,7,8 bits Tx and Rx possible by this s/w UART								  *
*  1 or 2 Stop bits as pre-defined by user									  *
*  Possible to use parity bit (even or odd) along with data frame						  *
*******************************************************************************************************************
*/

volatile long int 				baudrate;
#define EVEN 0
#define ODD 1

#define NO 0
#define YES 1
/*************************************** PORT to be used for Tx and Rx *********************************************/
#define UART_RXPIN   PIND
#define UART_RXDDR   DDRD
#define UART_RXBIT   PD3
#define UART_RXPORT  PORTD

#define UART_TXPORT  PORTD
#define UART_TXDDR   DDRD
#define UART_TXBIT   PD2
/********************************************************************************************************************/

/************************* Define Oscillator frequency and required baud rate for UART here *************************/
#define CPU_CLOCK_HZ 20000000
#define BAUD_RATE 4800
/********************************************************************************************************************/

/**************************** Define number of data bits and number of stop bits here *******************************/
#define NUM_OF_DATABITS 8
#define NUM_OF_STOPBITS 1
/********************************************************************************************************************/


/************************************ Make U2X2 1 to double Baud rate ***********************************************/
#define U2X2 0
/********************************************************************************************************************/

/**************************** Define if you want to use Parity bit in SW UART here *********************************/
/****************************** If using parity bit define whether EVEN or ODD Parity *******************************/
#define PARITY_BIT NO
#define PARITY ODD 
/********************************************************************************************************************/

/***********************************  Timer 0 is set according to BAUD_RATE  ****************************************/
/*Here Timer 0 of Atmega 128 is used. Change the timer reqisters accordingly for other microcontrollers*/
void timer0_init(void)
{
	TCNT0=0x0;
	TIMSK0=0x03;
//	TCCR0B=0x0b;					// Prescalar 32
	TCCR0A = 0x02;
	TCCR0B = 0x02;					//Prescalar 8
	OCR0A=(CPU_CLOCK_HZ)/8/(baudrate)/3;
	sei();
}
/********************************************************************************************************************/

